//
//  CunjianDetailVC.m
//  ProjectforHDX
//
//  Created by yinda on 2018/6/5.
//  Copyright © 2018年 H.DX. All rights reserved.
//

#import "CunjianDetailVC.h"
#import "CunQuDetailHeaderView.h"
#import "BottomOperationView.h"
//#import "LCOrderDetailCell.h"
#import "CunOrquDetailCell.h"


//修改
#import "CSNewOrderLCVC.h"
#import "CSNewOrderServiceVC.h"
#import "CSNewOrderManageVC.h"
#import "CSNewOrderReplaceVC.h"

//安排发货
#import "DeliveryPartReplaceVC.h"
#import "CSSettleDeliveryUpdatePlateTVC.h"

//查看物流
#import "CMyOrderCenterDetailCheck.h"
#import "DeliverModel.h"
#import "MainVC.h"
#import "OperationtipsView.h"
#import "CunquHomeVC.h"
#import "CacheVC.h"
#import "PickupcodeVC.h"

@interface CunjianDetailVC ()<UITableViewDataSource,UITableViewDelegate>{
    UIView *bottomView;
    OperationtipsView *feedabackView;
    UIView *bagview;
    
}

@property (nonatomic, strong)UITableView *tableView;

/**
 *  订单详情总字典
 */
@property (nonatomic, strong)NSMutableDictionary *dataDict;

/**
 *  物流字典
 */
@property (nonatomic, strong)NSMutableDictionary *logisticsDict;


/**
 *  订单状态字典
 */
@property (nonatomic, strong)NSMutableDictionary *orderStatusDict;

/**
 *  订单类型字典
 */
@property (nonatomic, strong)NSMutableDictionary *orderTypeInfoDict;


/**
 *  板件信息字典，里面是板件数组
 */
@property (nonatomic, strong)NSMutableDictionary *platesInfoDict;


/**
 *  板件数组
 */
@property (nonatomic, strong)NSMutableArray *platesArray;


/**
 *  收获联系人信息
 */
@property (nonatomic, strong)NSMutableDictionary *receiverInfoDict;

/**
 *  备注
 */
@property (nonatomic, strong)NSString *remark;

/**
 *  1准时送达  2延时送达
 */
@property (nonatomic, strong)NSString *arriveStatus;
@end

@implementation CunjianDetailVC

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc]init]];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [bagview removeFromSuperview];
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self UIConfig];
    if (!self.serialNumber) {
        // 不是存件过来的请求详情接口
         [self getOrderDetails];
    }
    else{
        self.orderStatusDict = [[NSMutableDictionary alloc]init];
        self.receiverInfoDict = [[NSMutableDictionary alloc]init];
        [self.orderStatusDict setObject:self.serialNumber forKey:@"orderCode"];
        [self.orderStatusDict setObject:[self getCurrentTimes] forKey:@"orderTime"];
        THUserInfoModel *userModel = [THMangerTool getAccountInfo];
        [self.receiverInfoDict setObject:userModel.address forKey:@"receiverAddress"];
        NSString *phoneAndName = [NSString stringWithFormat:@"%@  %@",userModel.realName,userModel.telephone];
        [self.receiverInfoDict setObject:phoneAndName forKey:@"receiverName"];
        self.platesArray = [UtilCheck arraytoModel:self.partArr targetModel:@"CunQuDetailModel"];
        [self setupBottomView];
        
    }
}

-(NSString*)getCurrentTimes{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm"];
    NSDate *datenow = [NSDate date];
    NSString *currentTimeString = [formatter stringFromDate:datenow];
    NSLog(@"currentTimeString =  %@",currentTimeString);
    return currentTimeString;
}
- (void)dataConfig{
    
    self.logisticsDict = [[NSMutableDictionary alloc]init];
    self.orderStatusDict = [[NSMutableDictionary alloc]init];
    self.orderTypeInfoDict = [[NSMutableDictionary alloc]init];
    self.platesInfoDict = [[NSMutableDictionary alloc]init];
    self.platesArray = [[NSMutableArray alloc]init];
    self.receiverInfoDict = [[NSMutableDictionary alloc]init];
    self.remark = @"";
    
    [self.orderStatusDict setObject:[self.dataDict objectForKey:@"code"] forKey:@"orderCode"];
    [self.orderStatusDict setObject:[self.dataDict objectForKey:@"time"] forKey:@"orderTime"];
    [self.orderStatusDict setObject:self.isQujian forKey:@"cunqutype"];
//    self.orderStatusDict = [self.dataDict objectForKey:@"orderStatus"];
//    self.receiverInfoDict = [self.dataDict objectForKey:@"receiverInfo"];
    [self.receiverInfoDict setObject:[self.dataDict objectForKey:@"userAddress"] forKey:@"receiverAddress"];
    NSString *phoneAndName = [NSString stringWithFormat:@"%@  %@",[self.dataDict objectForKey:@"userName"],[self.dataDict objectForKey:@"userPhone"]];
    [self.receiverInfoDict setObject:phoneAndName forKey:@"receiverName"];

    self.logisticsDict = [self.dataDict objectForKey:@"logistics"];
    self.orderTypeInfoDict = [self.dataDict objectForKey:@"orderTypeInfo"];
    self.remark = [self.dataDict objectForKey:@"remark"];
    self.platesInfoDict = [self.dataDict objectForKey:@"platesInfo"];
//    self.platesArray = [self.platesInfoDict objectForKey:@"plates"];
//     self.platesArray = [self.dataDict objectForKey:@"accessParts"];
    self.platesArray = [UtilCheck arraytoModel:[self.dataDict objectForKey:@"accessParts"] targetModel:@"CunQuDetailModel"];
    [self setupBottomView];
    
}

- (void)UIConfig{

    self.labnav.text = self.titlename;
    self.labnav.textColor = [UIColor whiteColor];
    self.labnav.backgroundColor = [UIColor clearColor];
    self.view.backgroundColor = [UIColor whiteColor];
    
    if ([self.isQujian isEqualToString:@"1"] && self.nohengping==NO) {
        self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0  ,self.view.height , self.view.width - 64 - 52)];
    }
    else{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0  ,self.view.width , self.view.height - 64 - 52)];
    }
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"CunOrquDetailCell" bundle:nil] forCellReuseIdentifier:@"CunOrquDetailCell"];
    
}

- (void)setupBottomView{
    CunQuDetailHeaderView *headView = [[CunQuDetailHeaderView alloc]initHeaderViewWithOrderStatusDic: self.orderStatusDict  AndReceiverDict:self.receiverInfoDict AndlogisticsDict:self.logisticsDict AndOrderTypeInfoDict:self.orderTypeInfoDict];
    self.tableView.tableHeaderView = headView;
    if (self.serialNumber) {
        UIView *footView = [[UIView alloc]init];
        UIImageView *grayimageView;
        if ([self.isQujian isEqualToString:@"1"]) {
           grayimageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_HEIGHT, 1)];//   灰色隔线
        }
        else{
           grayimageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1)];//   灰色隔线
        }
        grayimageView.backgroundColor = [UIColor grayColor];
        [footView addSubview:grayimageView];
        footView.top =  self.tableView.bottom;
        footView.left = self.view.left;
        if ([self.isQujian isEqualToString:@"1"]) {
             footView.size = CGSizeMake(SCREEN_HEIGHT, 52);
        }
        else{
        footView.size = CGSizeMake(SCREEN_WIDTH, 52);
        }
        //    footView.frame = CGRectMake(0,SCREEN_HEIGHT-52-100, self.view.frame.size.width, 52);
        // 取消存件取件
        UIButton *cancerButton = [UIButton buttonWithType:0];
        [cancerButton setTitle:[UtilCheck language:@"cunDetail.cancer"] forState:0];
        if ([self.isQujian isEqualToString:@"1"]) {
            [cancerButton setTitle:[UtilCheck language:@"cunDetail.cancerOrder"] forState:0];
        }
        [cancerButton setTitleColor:[UIColor grayColor] forState:0];
        if ([self.isQujian isEqualToString:@"1"]) {
         cancerButton.frame = CGRectMake(SCREEN_HEIGHT-90-10-80, 11, 80, 30);
        }
        else{
        cancerButton.frame = CGRectMake(SCREEN_WIDTH-90-10-80, 11, 80, 30);
        }
        [cancerButton setBackgroundImage:[UIImage imageNamed:@"取消存件"] forState:0];
        [cancerButton addTarget:self action:@selector(cancerAction) forControlEvents:UIControlEventTouchUpInside];
        [footView addSubview:cancerButton];
        
        // 确定存件取件
        UIButton *sureButton = [UIButton buttonWithType:0];
        [sureButton setTitle:[UtilCheck language:@"cunDetail.sure"] forState:0];
        if ([self.isQujian isEqualToString:@"1"]) {
        [sureButton setTitle:[UtilCheck language:@"开箱"] forState:0];
        }
        [sureButton setTitleColor:[UIColor whiteColor] forState:0];
        if ([self.isQujian isEqualToString:@"1"]) {
            sureButton.frame = CGRectMake(SCREEN_HEIGHT-90, 11, 80, 30);
        }
        else{
            sureButton.frame = CGRectMake(SCREEN_WIDTH-90, 11, 80, 30);
        }
        [sureButton setBackgroundImage:[UIImage imageNamed:@"确认存件"] forState:0];
        
        [sureButton addTarget:self action:@selector(sureAction:) forControlEvents:UIControlEventTouchUpInside];
        [footView addSubview:sureButton];
        
        // 共多少件
        UILabel *tallLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 15, 100, 21)];
        tallLabel.textColor = [UIColor grayColor];
        tallLabel.font = [UIFont systemFontOfSize:15];
        NSString *content = [NSString stringWithFormat:[UtilCheck language:@"setting.tallCount"],(int)self.number];
        NSRange range = [content rangeOfString:[NSString stringWithFormat:@"%d",(int)self.partArr.count]];
        NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:content];
        [attrString addAttribute:NSForegroundColorAttributeName
                           value:[UIColor blueColor]
                           range:range];
        tallLabel.attributedText = attrString;
        
        [footView addSubview:tallLabel];
        
        [self.view addSubview:footView];
    }
    
//    NSArray *arr= [[self.orderStatusDict objectForKey:@"operation"] componentsSeparatedByString:@","];
//    if (arr.count == 0) {
//        return;
//    }else if (arr.count == 1){
//        if ([arr[0] isKindOfClass:[NSString class]]) {
//            if ([arr[0] length] <= 0) {
//                return;
//            }
//        }else{
//            return;
//        }
//    }
//    //    1取消订单2修改订单，3安排发货，4确认订单，5继续发货，6确认收货，7查看物流
//    BottomOperationView *footView2 = [[BottomOperationView alloc]initWithOperationArray:arr AndOperationType:@"order" btnClick:^(long tag) {
//        [self btnClick:tag];
//    }];
    
//    [self.view addSubview:footView2];
//    [footView2 setFrame:CGRectMake(0, self.tableView.bottom, self.view.width, 52)];
    
}
#pragma mark 网络请求
// 取消存件
- (void)cancerAction{
    NSString *type;
    if ([self.isQujian isEqualToString:@"1"]) {
        type = @"2";
    }
    else{
        type = @"1";
    }
    NSDictionary *dic = @{@"type":type,@"code":self.serialNumber};
    [[BDHUD sharedManager] showBDHUD:self.view title:[THMangerTool language:@"HUD.title"]];
    [AFHttpTool postJsonDatawithUrl:@"cancelSaveOrPick" parameters:dic success:^(id responseObject) {
        [[BDHUD sharedManager] dismissHUD];
        if ([[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] == 1) {
            [self.navigationController popViewControllerAnimated:YES];
            [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
        }else {
            
            [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
        }
        
    } fail:^(id responseObject, NSError *error) {
        
        [[BDHUD sharedManager] dismissHUD];
        
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
    }];
    
}

// 确认订单
- (void)sureAction:(UIButton *)bt{
     NSString *type;
    // 取件开箱
    if ([self.isQujian isEqualToString:@"1"]) {
        [self getBox:bt type:@"2"];
    }
    else{
        type = @"1";
        NSDictionary *dic1 = @{@"type":type,@"code":self.serialNumber,@"parts":self.partArr};
        [[BDHUD sharedManager] showBDHUD:self.view title:[THMangerTool language:@"HUD.title"]];
        // 存件
        bt.enabled = NO;
        [AFHttpTool postJsonDatawithUrl:@"cconfirmSaveOrPick" parameters:dic1 success:^(id responseObject) {
            [[BDHUD sharedManager] dismissHUD];
            bt.enabled = YES;
            if ([[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] == 1) {
                // 存件成功显示这层
                [self showZhenceng];
            }else {
                
                [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            }
            
        } fail:^(id responseObject, NSError *error) {
            
            [[BDHUD sharedManager] dismissHUD];
            bt.enabled = YES;
            if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
                [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
            }else {
                [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
            }
        }];
    }
    
}

// 打开智能柜箱子
- (void)getBox:(UIButton *)bt type:(NSString *)type{
//    NSString *type =  self.isFaultypiece;
    // 打开箱门
    bt.enabled = NO;
    // 打开箱门
    [[BDHUD sharedManager] showBDHUD:self.view title:[THMangerTool language:@"HUD.title"]];
    [AFHttpTool postJsonDatawithUrl:@"cconfirmSaveOrPick" parameters:@{@"type":type,@"code":self.serialNumber,@"parts":self.partArr}
                            success:^(id responseObject) {
                                bt.enabled = YES;
                                [[BDHUD sharedManager] dismissHUD:self.view];
                                if(1==[[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue]){
                                    [[BDHUD sharedManager]showWords:[UtilCheck language:@"箱门打开成功"]];
                                    PickupcodeVC *vc = [[PickupcodeVC alloc]init];
                                    vc.cabinetCode = self.cabinetCode;
//                                    vc.boxcode = [[responseObject objectForKey:@"data"]objectForKey:@"boxCode"]; // 箱号
//                                    vc.boxID = [[responseObject objectForKey:@"data"]objectForKey:@"boxID"]; // 箱号ID
//                                    vc.freenumber = [[responseObject objectForKey:@"data"]objectForKey:@"number"]; // 空余数量
                                    vc.serialNumber = self.serialNumber; // 流水号
                                    vc.type = type;
                                    vc.transferArray = self.partArr;
                                    [self.navigationController pushViewController:vc animated:YES];
                                }
                                else{
                                    NSLog(@"%@",[responseObject objectForKey:@"head"][@"info"]);
                                    [[[UIAlertView alloc]initWithTitle:[UtilCheck language:@"CachVC.kaixaingtishi"] message:[responseObject objectForKey:@"head"][@"info"] delegate:self cancelButtonTitle:[UtilCheck language:@"show.gotIt"] otherButtonTitles:nil, nil]show];
                                }
                            } fail:^(id responseObject, NSError *error) {
                                [[BDHUD sharedManager] dismissHUD:self.view];
                                bt.enabled = YES;
                                NSLog(@"打开箱门失败");
                                [[[UIAlertView alloc]initWithTitle:[UtilCheck language:@"CachVC.kaixaingtishi"] message:[responseObject objectForKey:@"head"][@"info"] delegate:self cancelButtonTitle:[UtilCheck language:@"show.gotIt"] otherButtonTitles:nil, nil]show];
                                
                            }];
}

// 存件成功提示遮层
- (void)showZhenceng{
    //1. 取出window
    UIWindow * window = [[UIApplication sharedApplication] keyWindow];
    //2. 创建背景视图
    bagview = [[UIView alloc]init];
    bagview.frame = window.bounds;
    //3. 背景颜色可以用多种方法
    bagview.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.4];
    [window addSubview:bagview];
    //4. 把需要展示的控件添加上去
    feedabackView = [[NSBundle mainBundle]loadNibNamed:@"OperationtipsView" owner:self options:nil].firstObject;
    feedabackView.layer.cornerRadius = 7;
    feedabackView.layer.masksToBounds = YES;
    [feedabackView.knowButton setTitle:[UtilCheck language:@"show.gotIt"] forState:UIControlStateNormal];
    [feedabackView.knowButton addTarget:self action:@selector(hideAlertView) forControlEvents:UIControlEventTouchUpInside];
    [bagview addSubview:feedabackView];
    feedabackView.isCun = self.isQujian;
    //5. 动画简单(low)
    [UIView animateWithDuration:0.15 animations:^{
        NSInteger orangey = [self.isQujian isEqualToString:@"0"] ? 200 : 100;
        feedabackView.frame = CGRectMake((self.view.frame.size.width-280)/2, orangey, 280, 220);
    }];
    //6.给背景添加一个手势，后续方便移除视图
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideAlertView)];
    [bagview addGestureRecognizer:tap];
}
- (void)hideAlertView{
    //动画简单(low)
    [UIView animateWithDuration:0.3 animations:^{
        feedabackView.frame = CGRectMake(0, SCREEN_HEIGHT, 280, 180);
    }];
    // 延迟几秒移除视图
    [self performSelector:@selector(remove) withObject:nil afterDelay:0.3];
}

- (void)remove{
    [bagview removeFromSuperview];
    AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    app.shouldChangeOrientation = NO;
    NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
    [[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"];
    NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
    CunquHomeVC *vc = [[CunquHomeVC alloc]init];
    if (self.cabinetCode==nil) {
         NSString *cabinetCode = [[NSUserDefaults standardUserDefaults]objectForKey:@"cabinetCode"];
        vc.cabinetCode = cabinetCode;
    }
    else{
        vc.cabinetCode = self.cabinetCode;
    }
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark tableview delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSLog(@"cell的个数是:%ld",self.platesArray.count);
//    return 2;
    return self.platesArray.count;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 195.0f;
}



-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    LCOrderDetailCell *   cell = (LCOrderDetailCell*)[tableView dequeueReusableCellWithIdentifier:@"LCOrderDetailCell"];
//
//    if(cell == nil)
//    {
//        cell = [[LCOrderDetailCell alloc] init];
//    }
//    NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithDictionary:self.platesArray[indexPath.row]];
//
//    cell.type = [self.orderTypeInfoDict objectForKey:@"orderType"];
//    [cell setDataDict: dict];
//
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//
//    cell.needNum = YES;
//    if (indexPath.row != 0) {
//        cell.needNum = NO;
//    }
//
//    cell.indexLab.text = [NSString stringWithFormat:@"%ld",indexPath.row + 1];
//    cell.repairNumLab.text = [NSString stringWithFormat:@"%@:%ld",[THMangerTool language:@"order.unit"],self.platesArray.count];
    CunOrquDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CunOrquDetailCell" forIndexPath:indexPath];
    cell.selectionStyle = 0;
    cell.model = self.platesArray[indexPath.row];
    return cell;
    
}

#pragma mark  底部按钮点击
/**
 *  按钮点击
 *sender.tag 1取消订单2修改订单，3安排发货，4确认订单，5继续发货，6确认收货，7查看物流
 *  @param sender
 */
-(void)btnClick:(long)sender{
    
    THUserInfoModel *userModel=[THMangerTool getAccountInfo];
    
}


#pragma mark 网络请求
/**
 *  获取订单详情
 */
- (void)getOrderDetails {
    
    [[BDHUD sharedManager] showBDHUD:self.view title:nil];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"code"]=self.orderCode;
    NSString *type;
    if ([self.isQujian isEqualToString:@"1"]) {
        type = @"2";
    }
    else{
        type = @"1";
    }
    [params setObject:type forKey:@"type"];
//    [params setObject:@"1" forKey:@"Page"];
//    [params setObject:@"10" forKey:@"Size"];
//    params[@"orderCode"]=@"SCRAP00082";
    [AFHttpTool postJsonDatawithUrl:@"getAccessDetail" parameters:[params mutableCopy] success:^(id responseObject) {
        
        [[BDHUD sharedManager] dismissHUD];
        
        if(1 == [[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] ) {
            self.dataDict = [[NSMutableDictionary alloc]initWithDictionary: [responseObject objectForKey:@"data"]];
            
            [self dataConfig];
            
            NSLog(@"订单详情数据%@",self.dataDict);
            
            if (self.dataDict != nil) {
                [self dataConfig];
                [self setupBottomView];
                [self.tableView reloadData];
            }
            else {
                self.tableView.tableHeaderView = nil;
                [[BDHUD sharedManager] showNOneDataViewHUD:self.tableView  top:30 title:[THMangerTool language:@"HUD.noOrderData"]  onClick:nil];
            }
        }
        else {
            
            //返回数据出问题 弹出服务器返回信息
            if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            }
        }
        
    } fail:^(id responseObject, NSError *error) {
        
        [[BDHUD sharedManager] dismissHUD];
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
        
        
    }];
}

/**
 *  取消订单
 */
- (void)cancelOrderDetails {
    
    [[BDHUD sharedManager] showBDHUD:self.view title:nil];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"orderCode"]=self.orderCode;
    [AFHttpTool postJsonDatawithUrl:@"cancelOrder"  parameters:[params mutableCopy] success:^(id responseObject) {
        
        [[BDHUD sharedManager] dismissHUD];
        
        if(1 == [[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] ) {
            
            [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            [self.navigationController popViewControllerAnimated:YES];
            
        }
        else {
            
            //返回数据出问题 弹出服务器返回信息
            if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            }
        }
        
    } fail:^(id responseObject, NSError *error) {
        
        [[BDHUD sharedManager] dismissHUD];
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
        
        
    }];
}


/**
 *  确认订单
 */
- (void)confirmOrderDetails {
    
    [[BDHUD sharedManager] showBDHUD:self.view title:nil];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"orderCode"]=self.orderCode;
    [params setObject:@"1" forKey:@"type"];
    [params setObject:_partArr forKey:@"parts"];
    [AFHttpTool postJsonDatawithUrl:@"confirmOrder"  parameters:[params mutableCopy] success:^(id responseObject) {
        
        [[BDHUD sharedManager] dismissHUD];
        
        if(1 == [[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] ) {
            
            [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            [self getOrderDetails];
            [self.tableView reloadData];
            
        }
        else {
            
            //返回数据出问题 弹出服务器返回信息
            if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            }
        }
        
    } fail:^(id responseObject, NSError *error) {
        
        [[BDHUD sharedManager] dismissHUD];
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
        
        
    }];
}


@end
